//
//  OrderByNode.m
//  DataCollector
//
//  Created by jiro on 12/06/28.
//  Copyright 2012 jiro music. All rights reserved.
//

#import "OrderByNode.h"

#import "../../Commons.h"
#import "ExpressionNode.h"

OrderByNode::OrderByNode( const ExpressionNode& fieldNodesArg, bool isAscArg )
{
	isAsc = isAscArg;
	fieldNodes = new ExpressionNode( fieldNodesArg );
}

OrderByNode::OrderByNode( NSString* fieldName, bool isAscArg )
{
	isAsc = isAscArg;
	fieldNodes = new FieldNode( fieldName );
}

OrderByNode::~OrderByNode()
{
	delete fieldNodes;
}

NSString* OrderByNode::query() const
{
	NSString* s = [ NSString stringWithFormat: @" order by %@ %@", fieldNodes->query(), isAsc ? @" asc " : @" desc " ];
	return s;
}